package com.xhxi.photobooker.controller;

import com.xhxi.photobooker.entity.Announcement;
import com.xhxi.photobooker.result.Result;
import com.xhxi.photobooker.service.AnnouncementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/announcement")
public class    AnnouncementController {
    @Autowired
    private AnnouncementService announcementService;

    @GetMapping("/list")
    public Result<List<Announcement>> getAll() {
        return Result.success(announcementService.getAll());
    }

    @GetMapping("/latest")
    public Result<Announcement> getLatest() {
        return Result.success(announcementService.getLatest());
    }

    @PostMapping("/add")
    public Result<Boolean> add(@RequestBody Announcement announcement) {
        announcementService.add(announcement);
        return Result.success(true);
    }

    @DeleteMapping("/{id}")
    public Result<Boolean> delete(@PathVariable Long id) {
        announcementService.delete(id);
        return Result.success(true);
    }

    @PutMapping("/{id}")
    public Result<Boolean> update(@PathVariable Long id, @RequestBody Announcement announcement) {
        announcement.setId(id);
        announcementService.update(announcement);
        return Result.success(true);
    }
} 